var income = new Vue({
	el: "#app",
	data: {
		data: '',
		storeId: '',
		type: [{
			label: "全部分类",
			value:0
		}, {
			label: "已优惠",
			value:1
		}, {
			label: "无优惠",
			value:2
		}, ],
		typeList: '全部分类',
		incomeType:0,
		flows: {
			month_total:{},
		},
	},
	//计算属性
	computed: {},
	//监听属性
	watch: {},
	//钩子函数
	created() {
		var searchUrl = window.location.href;
		var searchData = searchUrl.split("="); //截取 url中的“=”,获得“=”后面的参数
		var searchText = decodeURI(searchData[1]); //decodeURI解码
		this.storeId = searchText
	},
	mounted() {
		this.getDate();
		this.getIncome();
	},
	methods: {
		getDate() {
			nowDate = new Date();
			let date = {
				year: nowDate.getFullYear(),
				month: nowDate.getMonth() + 1,
			}
			this.data = date.year + '-' + date.month;
		},

		// 选择日期
		chooseTime() {
			var that = this;
			weui.datePicker({
				start: 2006,
				end: new Date().getFullYear(),
				defaultValue: [new Date().getFullYear(), new Date().getMonth() + 1],
				depth: 2,
				onChange: function(result) {
					that.data = result[0].value + '-' + result[1].value
				},
				onConfirm: function(result) {
					that.data = result[0].value + '-' + result[1].value
					s5.initData({
						url: '/user-income',
						type: 'post',
						data: {
							store_id: that.storeId,
							date: that.data,
							type: that.incomeType
						},
					}, (res) => {
						var data = JSON.parse(res)
						that.flows = data.data
						if (data.code != 200) {
							weui.confirm(data.msg, {
								title: '温馨提示',
								buttons: [{
									label: 'NO',
									type: 'default',
									onClick: function() {
										console.log('no')
									}
								}, {
									label: 'YES',
									type: 'primary',
									onClick: function() {
										window.location.href = 'index.html'
										console.log('yes')
									}
								}]
							});
						}
					})
				}
			});
		},
		// 选择类型
		chooseType() {
			var that = this;
			weui.picker(that.type, {
				defaultValue: [0],
				onChange: function(result) {
					that.typeList = result[0].label
					if (that.typeList == "全部分类") {
						that.incomeType = 0;
					} else if (that.typeList == "已优惠") {
						that.incomeType = 1;
					} else {
						that.incomeType = 2;
					}
				},
				onConfirm: function(result) {
					that.typeList = result[0].label
					if (that.typeList == "全部分类") {
						that.incomeType = 0;
					} else if (that.typeList == "已优惠") {
						that.incomeType = 1;
					} else {
						that.incomeType = 2;
					}
					s5.initData({
						url: '/user-income',
						type: 'post',
						data: {
							store_id: that.storeId,
							date: that.data,
							type: that.incomeType
						},
					}, (res) => {
						var data = JSON.parse(res)
						that.flows = data.data
						if (data.code != 200) {
							weui.confirm(data.msg, {
								title: '温馨提示',
								buttons: [{
									label: 'NO',
									type: 'default',
									onClick: function() {
										console.log('no')
									}
								}, {
									label: 'YES',
									type: 'primary',
									onClick: function() {
										window.location.href = 'index.html'
										console.log('yes')
									}
								}]
							});
						}
					})
				}
			})

		},
		// 收入明细
		getIncome() {
			var that = this;
			s5.initData({
				url: '/user-income',
				type: 'post',
				data: {
					store_id: that.storeId,
					date: that.data,
					type: that.incomeType
				},
			}, (res) => {
				var data = JSON.parse(res)
				that.flows = data.data
				if (data.code != 200) {
					weui.confirm(data.msg, {
						title: '温馨提示',
						buttons: [{
							label: 'NO',
							type: 'default',
							onClick: function() {
								console.log('no')
							}
						}, {
							label: 'YES',
							type: 'primary',
							onClick: function() {
								window.location.href = 'index.html'
								console.log('yes')
							}
						}]
					});
				}
			})
		},
		toIncomeDetail(id) {
			window.location.href = "user-income-detail.html?id=" + id
		}
	}
})
